package com.example.sunmiv1.adapter;


import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.example.sunmiv1.R;
import com.example.sunmiv1.entity.AllocationTubeBean;
import com.example.sunmiv1.utils.Tools;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class AllocationTubeListAdapter extends RecyclerView.Adapter<AllocationTubeListAdapter.atlHolder> {
    private List<AllocationTubeBean.DataBean> mList;
    private ClickListener mClickListener;

    public AllocationTubeListAdapter(List<AllocationTubeBean.DataBean> list) {
        super();
        mList = list;
    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    @Override
    public atlHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_allocation_tube_list, parent, false);
        return new atlHolder(view);
    }

    @Override
    public void onBindViewHolder(atlHolder holder, int position) {
        holder.tvStatus.setText(mList.get(position).getExamine_name());
        holder.tvAlloTime.setText(mList.get(position).getAdd_time());
        holder.tvAlloOrderNo.setText(mList.get(position).getOrder_number());
        holder.tvStoreName.setText(mList.get(position).getTransfer_name());
        if (mList.get(position).getWarehousing_status().equals("1")) {
            holder.llToWarehouseTime.setVisibility(View.VISIBLE);
            holder.groupTotalAct.setVisibility(View.VISIBLE);
            holder.groupReallyMoney.setVisibility(View.VISIBLE);
            holder.tvDetailToWarehouse.setVisibility(View.VISIBLE);

            holder.tvWarehouseTime.setText(mList.get(position).getWarehouse_time());
            holder.tvTotalAct.setText(String.valueOf(mList.get(position).getReal_goods_species()));
            holder.tvReallyMoney.setText(String.valueOf(mList.get(position).getReal_money_total()));
            holder.tvDetailToWarehouse.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mClickListener.setClickListener(v, position);
                }
            });
        } else {
            holder.llToWarehouseTime.setVisibility(View.GONE);
            holder.groupTotalAct.setVisibility(View.GONE);
            holder.groupReallyMoney.setVisibility(View.GONE);
            holder.tvDetailToWarehouse.setVisibility(View.GONE);
        }
        Tools.hideViewInItem(mList.get(position).getRemarks(), holder.tvRemark);

        if (mList.get(position).getExamine_status().equals("0")) {
            holder.viewLine.setVisibility(View.VISIBLE);
            holder.groupOkOrNo.setVisibility(View.VISIBLE);
            holder.btnAccpet.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mClickListener.setClickListener(v, position);
                }
            });
            holder.btnReject.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mClickListener.setClickListener(v, position);
                }
            });
        } else {
            holder.viewLine.setVisibility(View.GONE);
            holder.groupOkOrNo.setVisibility(View.GONE);
        }
        holder.tvDetailAllo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mClickListener.setClickListener(v, position);
            }
        });


    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    @OnClick({R.id.tv_detail_allo, R.id.tv_detail_to_warehouse, R.id.btn_accpet, R.id.btn_reject})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_detail_allo:
                break;
            case R.id.tv_detail_to_warehouse:
                break;
            case R.id.btn_accpet:
                break;
            case R.id.btn_reject:
                break;
        }
    }

    static class atlHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_status)
        TextView tvStatus;
        @BindView(R.id.tv_allo_time)
        TextView tvAlloTime;
        @BindView(R.id.tv_warehouse_time)
        TextView tvWarehouseTime;
        @BindView(R.id.ll_to_warehouse_time)
        LinearLayout llToWarehouseTime;
        @BindView(R.id.tv_allo_orderNo)
        TextView tvAlloOrderNo;
        @BindView(R.id.tv_store_name)
        TextView tvStoreName;
        @BindView(R.id.tv_total_act)
        TextView tvTotalAct;
        @BindView(R.id.group_total_act)
        LinearLayout groupTotalAct;
        @BindView(R.id.tv_reallyMoney)
        TextView tvReallyMoney;
        @BindView(R.id.group_reallyMoney)
        LinearLayout groupReallyMoney;
        @BindView(R.id.tv_remark)
        TextView tvRemark;
        @BindView(R.id.group_remark)
        LinearLayout groupRemark;
        @BindView(R.id.tv_detail_allo)
        TextView tvDetailAllo;
        @BindView(R.id.tv_detail_to_warehouse)
        TextView tvDetailToWarehouse;
        @BindView(R.id.view_line)
        View viewLine;
        @BindView(R.id.btn_reject)
        TextView btnReject;
        @BindView(R.id.btn_accpet)
        TextView btnAccpet;
        @BindView(R.id.group_ok_or_no)
        LinearLayout groupOkOrNo;

        public atlHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface ClickListener {
        void setClickListener(View view, int positon);
    }

    public void setViewClickListener(ClickListener clickListener) {
        mClickListener = clickListener;
    }

}
